package com.bdzl.base.controller;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdzl.common.bean.BaseResponse;
import com.bdzl.exception.ParameterException;
import com.bdzl.exception.SecurityException;

public class BaseController {
	 
    @ExceptionHandler				//当这个Controller中任何一个方法发生异常，一定会被这个方法拦截到 
    @ResponseBody
    public BaseResponse exc(Exception e) {
    	BaseResponse baseResponse = new BaseResponse();
    	
    	try {
    		throw e;
    	} catch (ParameterException ex) {
    		baseResponse.setStateCode(((ParameterException) e).getCode());
    		baseResponse.setStateMessage(e.getMessage());
    	} catch (SecurityException ex) {
    		baseResponse.setStateCode(((SecurityException) e).getCode());
    		baseResponse.setStateMessage(e.getMessage());
    	} catch (Exception ex) {
    		ex.printStackTrace();
    		baseResponse.setStateCode(303);
        	baseResponse.setStateMessage("未知错误");
    	}
        return baseResponse;  
    	
    }
}
